<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <div id="main">
            <div id="content">
                <div id="masthead">
                    <span class="head">Ingresar Horario</span>
                    <ul class="breadcrumbs">
                        <li>
                            <?php
                            if ($this->session->userdata('tipo') == 1) {
                                echo "Administrador";
                            } else if ($this->session->userdata('tipo') == 2) {
                                echo "Jefe";
                            }else
                                echo "Usuario";
                            ?> : 
                            Hola <?php echo $this->session->userdata('username'); ?></li>

                    </ul>
                </div>
                <!-- ENDS Headline -->
                <div id="page-content-full">
                    <ul class="tabs">
                        <li><a href="#"><span>Cambiar Horarios</span></a></li>
                        <li><a href="#"><span>Ingresar Horario</span></a></li>                        

                    </ul>    
                    <div class="panes">
                        <div>
                            <br>

                            <div class="ui-widget">
                                <?php echo validation_errors(); ?>
                                <?php
                                $attributes = array('id' => 'form1');
                                echo form_open('configuraciones/delete', $attributes)
                                ?>
                                <label>Buscar usuario:</label>   
                                <input type="text" name="search" size="30" id= "search" onkeyup="auto('<?php echo $this->session->userdata('jefe') ?>')"  class="form-poshytip" title="Escriba el nombre o cédula del Usuario"/>
                                <input type="hidden" value="<?= base_url() ?>" id="hiddenurl" />
                            </div>
                            <br>
                            <div id="mensaje"></div>
                            <br>
                            <input type="submit" value="Cambiar" id="buscar" class="boton" />
                            <br>
                            <br>
                            <div id="info_usuario"><!--ajax...--></div>
                        </div>
                        <!--Agregar-->
                        <div>
                            <br>
                            <div class="ui-widget">
                                <label>Nombre de horario:</label>   
                                <input type="text" name="search" id= "search2" class="form-poshytip" title="Escriba el identificador del horario"/>
                                <input type="hidden" value="<?= base_url() ?>" id="hiddenurl" />
                            </div>
                            <br>
                            <div class="styled-select">
                                <label>Hora inicio:</label>
                                <select id="hour">
                                    <?php for ($x = 1; $x <= 23; $x++) { ?>
                                        <option value="<?= $x ?>"<?= (date("H") == $x ? ' selected="selected"' : '') ?>><?= $x ?></option>  
                                    <?php } ?>
                                </select> 
                                <select id="minute">
                                    <option value="00">00</option>
                                    <option value="15">15</option>
                                    <option value="30">30</option>
                                    <option value="45">45</option>
                                </select>
<!--                                <select id="period">
                                    <option value="pm">pm</option>
                                    <option value="am">am</option>
                                </select>-->
                                <!--<label>&nbsp;&nbsp;&nbsp;Hora final:</label>-->
                                <select id="hour2">
                                    <?php for ($x = 1; $x <= 23; $x++) { ?>
                                        <option value="<?= $x ?>"<?= (date("H") == $x ? ' selected="selected"' : '') ?>><?= $x ?></option>  
                                    <?php } ?>
                                </select> 
                                <select id="minute2">
                                    <option value="00">00</option>
                                    <option value="15">15</option>
                                    <option value="30">30</option>
                                    <option value="45">45</option>
                                </select>
<!--                                <select id="period">
                                    <option value="pm">pm</option>
                                    <option value="am">am</option>
                                </select>-->
                            </div>
                            <br>
                            <div id="error_usuario"></div>
                            <br>
                            <input type="submit" value="Agregar" id="agregar" class="boton" />
                            <br>
                            <br>
                            <div id="info2">
                                <!--ajax...-->
                            </div>
                        </div>


                    </div>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="shadow-main"></div>
    </body>

<!--    <script src="<?php echo base_url(); ?>js/autocomplete_Horario.js" type="text/javascript"></script>
    <script src="<?php echo base_url(); ?>js/autocomplete_usuario.js" type="text/javascript"></script>-->

    <script type="text/javascript">
        function auto(jefe){
            var searched = $('#search').val();
            var fullurl = $('#hiddenurl').val() + 'index.php/configuraciones/getResult/' + searched + '?ced='+jefe;
            $.getJSON(fullurl,function(result){
                $.getJSON(fullurl,function(result){
                    var elements = [];
                    $.each(result,function(i,val){
                        elements.push(val.nombre+' '+val.apellidos+", "+val.cedula);
                    })
                    
                    $('#search').autocomplete({                    
                        source : elements
                    })
                })
            })     
        }
        
        $('#buscar').click(function(){      
            var name = $("#search").val();
            var msj="";
            if(!name){
                alert('Ingrese una cédula o un nombre');
                return false;
            }
            if(name.indexOf(',') != -1){
                var aux = name.substring(name.indexOf(',')+2);
                //hace = 1;
                if(aux != ""){
                    name = aux;
                }
            }else{
                msj ="Selecciones el usuario en las sugerencias,\n\para que la busqueda se mas precisa";
            }
            var form_data = {
                cedula: name,
                //                horario: $("#box").val(),
                msj: msj,
                ajax: '1'
            };

            $.ajax({
                url: "<?php echo site_url('configuraciones/Horario'); ?>",
                type: 'POST',
                data: form_data,
                success: function(msg){
                    $('#info_usuario').html(msg);
                }


            });
            return false; 
        });    
        //Ingresar
        $('#agregar').click(function(){              
            var name = $("#search2").val();
            var hour = $("#hour").val();
            var min = $("#minute").val();
            var hour2 = $("#hour2").val();
            var min2 = $("#minute2").val();
            if(!name){
                alert('Ingrese un nombre');
                return false;
            }
            var aux = name.substring(0,name.indexOf(' '));
            if(aux != ""){
                name = aux;
            }
            var form_data = {
                nombre: name,
                entrada : hour+":"+min+":00",
                salida : hour2+":"+min2+":00",
                hacer : 2,
                ajax: '1'
            };

            $.ajax({
                url: "<?php echo site_url('configuraciones/Ingresar_Horario'); ?>",
                type: 'POST',
                data: form_data,
                success: function(msg){
                    $('#info2').html(msg);
                    setTimeout('document.getElementById("info2").innerHTML="";',5000);
                }


            });
            return false; 
        });
        //Eliminar
        $('#eliminar').click(function(){              
            var name = $("#search3").val();
            if(!name){
                alert('Ingrese un nombre');
                return false;
            }
            var aux = name.substring(0,name.indexOf(' '));
            if(aux != ""){
                name = aux;
            }
            var form_data = {
                nombre: name,
                hacer : 3,
                ajax: '1'
            };

            $.ajax({
                url: "<?php echo site_url('configuraciones/Eliminar_Horario'); ?>",
                type: 'POST',
                data: form_data,
                success: function(msg){
                    $('#info3').html(msg);

                }


            });
            return false; 
        });

    </script>
</html>
